<template>
  <div>
    <!--客户信息-->
    <FormPanel
      ref="formList"
      :list="formList"
      formType="add"
      :cols="3"
      :labelWidth="105"
      :isSubmitBtn="false"
    />
    
    <!-- 列表  -->
    <el-tabs v-model="activeName" class="outer">
      <el-tab-pane label="车辆信息" name="first">
        <FilterTable
          ref="table"
          :columns="vehicle"
          :isSelectColumn="false"
          :params="fetchParams"
          :height="120"
          :onColumnsChange="vehicle => (this.vehicle = vehicle)"
        />
      </el-tab-pane>
    </el-tabs>   
    
    <!--回访内容-->
    <FormPanel
      ref="formList1"
      :list="formList1"
      formType="add"
      :cols="3"
      :labelWidth="105"
      :isSubmitBtn="false"
    />
    <!--操作按钮-->
    <div
      :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
    >
      <el-button @click="closeDialog">关闭</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import dictCode from '@/utils/dictCode';

// 生日提醒
import { getOwnerVehicle }  from '@/api/customerRepair/customerCare/guaranteedRemind/index';
import {  getSeries, getModel } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';

export default {
  mixins: [dictionary],
   props: {
    type: {
      type: String,
      default: 'add'
    },
    remindData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      // 表单绑定
      formList: this.createFormList(),
      formList1:this.createFormList1(),
      confirmBtnLoading: false,
      vehicle: this.getvehicle(),
      fetchParams: {},
      activeName: 'first',
      ownerNo:''
    };
  },
  created() {
    this.init();
    this.querySeries();
    this.queryModel();
  },
  methods: {
     init() {
      this.ownerNo = this.remindData.ownerNo;
      this.formList.forEach(x => {
        x.initialValue = this.remindData[x.fieldName];
      });
       this.formList1.forEach(x => {
        x.initialValue = this.remindData[x.fieldName];
      });
      // 查询车辆信息
      this.selectList();
    },
/** 返回表单对象 */
    createFormList() {
      return [
       {
          type: 'BREAK_SPACE',
          label: '车主信息'
        },
        {
          type: 'INPUT',
          label: '车主编码',
          fieldName: 'ownerNo',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车主名称',
          fieldName: 'cusName',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车主手机',
          fieldName: 'mobile',
          disabled: true
         },
        {
          type: 'INPUT',
          label: '车主电话',
          fieldName: 'phone',
          disabled: true
         },
         {
          type: 'INPUT',
          label: '联系人',
          fieldName: 'linkMan',
          disabled: true
         },
         {
          type: 'INPUT',
          label: '联系人电话',
          fieldName: 'telphone',
          disabled: true
         },
         {
          type: 'INPUT',
          label: '联系人手机',
          fieldName: 'linkPhone',
          disabled: true
         }
      ];
    },
    getvehicle() {
      return[
        { 
          title: '车系',
          dataIndex: 'SERIES',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '车型',
          dataIndex: 'MODEL',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '购车日期',
          dataIndex: 'SALES_DATE',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd'
        },
        { 
          title: '底盘号',
          dataIndex: 'VIN',
          sorter: true,
          editable: false
        },
        { 
          title: '质保日期',
          dataIndex: 'EXPIRATION_WARRANTY',
          sorter: true,
          editable: false,
          dateFormat: 'yyyy-MM-dd'
        },
        { 
          title: '牌照号',
          dataIndex: 'LICENSE',
          sorter: true,
          editable: false
        },
        { 
          title: '行驶里程',
          dataIndex: 'MILEAGE',
          sorter: true,
          editable: false
        },
        { 
          title: '车龄',
          dataIndex: 'AGE',
          sorter: true,
          editable: false,
          render: props => {
              return <span>{parseInt(props.row.AGE/12)+"年"+props.row.AGE%12+"月"}</span>;
          }
        },
        { 
          title: '最后维修日期',
          dataIndex: 'LAST_MAINTAIN_DATE',
          sorter: true,
          editable: false,
          dateFormat: 'yyyy-MM-dd'
        },
        { 
          title: '上次保养日期',
          dataIndex: 'LAST_MAINTENANCE_DATE',
          sorter: true,
          editable: false,
          dateFormat: 'yyyy-MM-dd'
        }
      ];
    },
    createFormList1(){
      return [
        {
          type: 'BREAK_SPACE',
          label: '关怀信息'
        },
        {
          type: 'SELECT',
          label: '关怀状态',
          fieldName: 'remindStatus',
          initialValue: '',
          itemList: this.createDictList('8206'),
          disabled:true
          },
        {
          type: 'SELECT',
          label: '关怀原因',
          fieldName: 'remindFailReason',
          initialValue: '',
          itemList: this.createDictList('8207'),
          disabled:true
        },
        {
          type: 'SELECT',
          label: '关怀结果',
          fieldName: 'remindResult',
          initialValue: '',
          itemList: this.createDictList('1075'),
          disabled:true
        },
        {
          type: 'CHECKBOX',
          label: '免打扰',
          fieldName: 'isDistruble',
          // initialValue: '10041001',
          options: { trueValue: 10041001, falseValue: 10041002 },
          disabled:true
        },
         {
          type: 'CHECKBOX',
          label: '需再次关怀',
          fieldName: 'ifNext',
          // initialValue: '10041001',
          options: { trueValue: 10041001, falseValue: 10041002 },
          disabled:true
        },
        {
          type: 'DATE',
          label: '下次关怀日期',
          fieldName: 'nextDate',
          initialValue: '', 
          disabled: true
         },
        {
          type: 'SELECT',
          label: '关怀方式',
          fieldName: 'remindWay',
          initialValue: '',
          itemList: this.createDictList('8208'),
          disabled:true
        },
        {
          type: 'INPUT',
          label: '其他建议',
          fieldName: 'customerFeedback',
          selfCols: 3,
          style: { height: '50px' },
          disabled:true
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'remark',
          selfCols: 3,
          style: { height: '50px' },
          disabled:true
        }
      ];
    },
    // 查询所有车系(供table使用)
    async querySeries() {
      const res = await getSeries();
      this.vehicle.find(x => x.dataIndex === 'SERIES').editItems = res.data.map(x => ({ text: x.SERIES_NAME, value: x.SERIES_ID + '' }));
    },
     // 查询所有车型(供table使用)
    async queryModel() {
      const res = await getModel();
      this.vehicle.find(x => x.dataIndex === 'MODEL').editItems = res.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_ID + '' }));
    },
    closeDialog(param) {
      this.$emit('close',param);
    },
    async selectList() {
      let infodata = await getOwnerVehicle(this.ownerNo);
      if (infodata.resultCode === 200) {
        this.$refs.table.$refs.pageTable.EXECUTE_INSERT(infodata.data);
      } else {
        this.$notify.error({ title: '提示信息', message: res.errMsg || '单据查询失败!' });
      } 
    }
  }
};
</script>